#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> nums(n), dp(n + 1);
    for (int i = 0; i < n; i++)
        cin >> nums[i];
    dp[2] = min(nums[0], nums[1]);
    int x1 = max(nums[0], nums[1]), x2 = dp[2];
    for (int i = 3; i <= n; i++)
    {
        if (nums[i - 1] <= x2)
            dp[i] = dp[i - 1];
        else if (nums[i - 1] > x1)
        {
            dp[i] = x1;
            x2 = x1;
            x1 = nums[i - 1];
        }
        else if (nums[i - 1] > x2 && nums[i - 1] <= x1)
        {
            dp[i] = nums[i - 1];
            x2 = nums[i - 1];
        }
    }
    int q;
    cin >> q;
    while (q--)
    {
        int x;
        cin >> x;
        cout << dp[x] << endl;
    }
    return 0;
}